package com.lzc.product.controller;

import com.lzc.product.model.Product;
import com.lzc.product.service.ProductService;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/productInfo.do")
public class ProductInfoServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        //获取商品编号
        String id = req.getParameter("id");
        ProductService service = new ProductService();
        //使用服务层对象获取商品信息
        Product product = service.getProductById(id);
        //将信息储存到请求对象中
        req.setAttribute("product",product);
        //跳转到商品详情页
        req.getRequestDispatcher("product.jsp").forward(req,resp);
    }
}